package com.haixin.security.web;


import com.haixin.security.bean.RolePermission;
import com.haixin.security.service.RolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/role-permissions")
public class RolePermissionController {
    @Autowired
    private RolePermissionService rolePermissionService;

    @GetMapping
    public List<RolePermission> getAllRolePermissions() {
        return rolePermissionService.getAllRolePermissions();
    }

    @GetMapping("/{roleId}")
    public List<Integer> getPermissionsByRoleId(@PathVariable int roleId) {
        return rolePermissionService.getPermissionsByRoleId(roleId);
    }

    @PostMapping
    public boolean addRolePermission(@RequestBody RolePermission rolePermission) {
        return rolePermissionService.addRolePermission(rolePermission);
    }

    @DeleteMapping("/role/{roleId}")
    public boolean removeRolePermissionsByRoleId(@PathVariable int roleId) {
        return rolePermissionService.removeRolePermissionsByRoleId(roleId);
    }

    @DeleteMapping
    public boolean removeRolePermission(@RequestBody RolePermission rolePermission) {
        return rolePermissionService.removeRolePermission(rolePermission);
    }
}
